﻿Imports System.Data.OleDb
Imports System.IO
Public Class Cls_Genius
    Private Sql_Con As New OleDbConnection(Cnn_String)
    Private Sql_Trn As OleDbTransaction
    Private Array_Depo_Kod(100) As String
    Private Stack_Depo_id As New Stack
    Private Stack_Depo_kod As New Stack
    Private Array_Kdv(100) As Integer
    Private Recete_Dt As New DataTable
    'kartlar
    Private Function StokBilgi(ByVal tarih As DateTime, ByVal depo As String, ByVal fyt As Integer, ByVal secenek As Integer) As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("Alis Kdv", GetType(Integer))
        dt.Columns.Add("Satis Kdv", GetType(Integer))
        dt.Columns.Add("Urun Tipi", GetType(Integer))
        dt.Columns.Add("Ana Grup", GetType(String))
        dt.Columns.Add("Alt Grup", GetType(String))
        dt.Columns.Add("Puan", GetType(Decimal))
        dt.Columns.Add("Barkod", GetType(String))
        dt.Columns.Add("Icerik", GetType(Integer))
        dt.Columns.Add("Barkod Tipi", GetType(String))
        dt.Columns.Add("Stok Kodu", GetType(String))
        dt.Columns.Add("Stok Adi", GetType(String))
        dt.Columns.Add("Fiyat", GetType(String))
        dt.Columns.Add("Birim", GetType(String))
        dt.Columns.Add("Birim Miktar", GetType(Integer))
        dt.Columns.Add("Fiyat2", GetType(String))
        dt.Columns.Add("Fiyat3", GetType(String))
        dt.Columns.Add("Fiyat4", GetType(String))
        dt.Columns.Add("Fiyat5", GetType(String))
        dt.Columns.Add("teminci", GetType(String))

        Dim cn As New OleDbConnection(Cnn_String)
        cn.Open()

        Dim cmd As New OleDbCommand("SELECT * FROM Q_GeniusAktarim", cn)
        If secenek = 0 Then 'tüm bilgiler
            cmd.CommandText = "SELECT * FROM Q_GeniusAktarim"
            cmd.Parameters.Add("@depoid", OleDbType.VarChar)
            cmd.Parameters.Add("@tarih", OleDbType.Date)
            cmd.Parameters.Item("@depoid").Value = depo
            cmd.Parameters.Item("@tarih").Value = New DateTime(1900, 1, 1, 0, 0, 0)
        ElseIf secenek = 1 Then
            cmd.CommandText = "SELECT * FROM Q_GeniusAktarim"
            cmd.Parameters.Add("@depoid", OleDbType.VarChar)
            cmd.Parameters.Add("@tarih", OleDbType.Date)
            cmd.Parameters.Item("@depoid").Value = depo
            cmd.Parameters.Item("@tarih").Value = New DateTime(tarih.Year, tarih.Month, tarih.Day, 0, 0, 0)
        Else
            cmd.CommandText = "SELECT * FROM Q_GeniusAktarim2"
            cmd.Parameters.Add("@depoid", OleDbType.VarChar)
            cmd.Parameters.Item("@depoid").Value = depo
        End If

        Dim rd As OleDbDataReader
        rd = cmd.ExecuteReader
        While rd.Read
            Dim alis_kdv As Integer
            If rd(0) Is DBNull.Value OrElse rd(0) Is Nothing OrElse rd(0) Is String.Empty Then
                alis_kdv = 0
            Else
                alis_kdv = CInt(rd(0))
            End If
            Dim aliskdvgrp As Integer
            If alis_kdv = 0 Then
                aliskdvgrp = 1
            ElseIf alis_kdv = 1 Then
                aliskdvgrp = 2
            ElseIf alis_kdv = 8 Then
                aliskdvgrp = 3
            ElseIf alis_kdv = 18 Then
                aliskdvgrp = 4
            ElseIf alis_kdv = 26 Then
                aliskdvgrp = 5
            End If
            Dim satis_kdv As Integer
            If rd(1) Is DBNull.Value OrElse rd(1) Is Nothing OrElse rd(1) Is String.Empty Then
                satis_kdv = 0
            Else
                satis_kdv = CInt(rd(1))
            End If
            Dim satiskdvgrp As Integer = satis_kdv
            'If satis_kdv = 0 Then
            '    satiskdvgrp = 1
            'ElseIf satis_kdv = 1 Then
            '    satiskdvgrp = 2
            'ElseIf satis_kdv = 8 Then
            '    satiskdvgrp = 3
            'ElseIf satis_kdv = 18 Then
            '    satiskdvgrp = 4
            'ElseIf satis_kdv = 26 Then
            '    satiskdvgrp = 5
            'End If
            Dim urun_tipi As Integer
            If rd(2) Is DBNull.Value OrElse rd(2) Is Nothing OrElse rd(2) Is String.Empty Then
                urun_tipi = 0
            Else
                urun_tipi = CInt(rd(2))
            End If
            Dim stk_ana_grup As String
            If rd(3) Is DBNull.Value OrElse rd(3) Is Nothing OrElse rd(3) Is String.Empty Then
                stk_ana_grup = " "
            Else
                stk_ana_grup = CStr(rd(3))
            End If
            Dim stk_alt_grup As String
            If rd(4) Is DBNull.Value OrElse rd(4) Is Nothing OrElse rd(4) Is String.Empty Then
                stk_alt_grup = " "
            Else
                stk_alt_grup = CStr(rd(4))
            End If
            Dim puan As Decimal
            If rd(5) Is DBNull.Value OrElse rd(5) Is Nothing OrElse rd(5) Is String.Empty Then
                puan = 0.0
            Else
                puan = CDec(rd(5))
            End If
            Dim barkod As String
            If rd(6) Is DBNull.Value OrElse rd(6) Is Nothing OrElse rd(6) Is String.Empty Then
                barkod = " "
            Else
                barkod = CStr(rd(6))
            End If

            Dim icerik As Integer
            If rd(7) Is DBNull.Value OrElse rd(7) Is Nothing OrElse rd(7) Is String.Empty Then
                icerik = 0
            Else
                icerik = CInt(rd(7))
            End If
            Dim tip_id As Integer
            If rd(8) Is DBNull.Value OrElse rd(8) Is Nothing OrElse rd(8) Is String.Empty Then
                tip_id = 0
            Else
                tip_id = CInt(rd(8))
            End If
            Dim tipkontrol As Integer
            If tip_id = 0 Then
                tipkontrol = 1
            ElseIf tip_id = 1 Then
                tipkontrol = 2
            ElseIf tip_id = 2 Then
                tipkontrol = 1
            ElseIf tip_id = 3 Then
                tipkontrol = 3
            ElseIf tip_id = 4 Then
                tipkontrol = 5
            ElseIf tip_id = 5 Then
                tipkontrol = 6
            End If

            'If Barkod_Tipi(tip_id) = 1 Then
            '    barkod = Barkod_Tipi(tip_id) & BarkodCevir(barkod)
            'Else
            '    barkod = Barkod_Tipi(tip_id) & barkod
            'End If
            Dim stok_code As String
            If rd(9) Is DBNull.Value OrElse rd(9) Is Nothing OrElse rd(9) Is String.Empty Then
                stok_code = " "
            Else
                stok_code = CStr(rd(9))
            End If
            Dim stok_adi As String
            If rd(10) Is DBNull.Value OrElse rd(10) Is Nothing OrElse rd(10) Is String.Empty Then
                stok_adi = " "
            Else
                stok_adi = CStr(rd(10))
            End If


            Dim depo_fiyat As String = "0"
            If rd(11) Is DBNull.Value OrElse rd(11) Is Nothing OrElse rd(11) Is String.Empty Then
                depo_fiyat = 0.0
            Else
                depo_fiyat = Format(rd(11), "000000.00")
            End If

            Dim genel_fiyat As String = "0"
            If rd(12) Is DBNull.Value OrElse rd(12) Is Nothing OrElse rd(12) Is String.Empty Then
                genel_fiyat = 0.0
            Else
                genel_fiyat = Format(rd(12), "000000.00")
            End If

            Dim fiyat As String = "0"
            If CDec(depo_fiyat) > 0 Then
                fiyat = depo_fiyat
            Else
                fiyat = genel_fiyat
            End If

            Dim birim_kod As String
            If rd(13) Is DBNull.Value OrElse rd(13) Is Nothing OrElse rd(13) Is String.Empty Then
                birim_kod = " "
            Else
                birim_kod = CStr(rd(13))
            End If
            Dim katsayi As Integer
            If rd(14) Is DBNull.Value OrElse rd(14) Is Nothing OrElse rd(14) Is String.Empty Then
                katsayi = 0
            Else
                katsayi = CInt(rd(14))
            End If


            Dim fiyat2 As String = "0"
            If Not rd(18) Is DBNull.Value And Not rd(18) Is Nothing And Not rd(18) Is String.Empty Then
                fiyat2 = Format(rd(18), "000000.00")
            Else
                If Not rd(17) Is DBNull.Value And Not rd(17) Is Nothing And Not rd(17) Is String.Empty Then
                    fiyat2 = Format(rd(17), "000000.00")
                Else
                    fiyat2 = Format(0, "000000.00")
                End If
            End If

            Dim fiyat3 As String = "0"
            If Not rd(20) Is DBNull.Value And Not rd(20) Is Nothing And Not rd(20) Is String.Empty Then
                fiyat3 = Format(rd(20), "000000.00")
            Else
                If Not rd(19) Is DBNull.Value And Not rd(19) Is Nothing And Not rd(19) Is String.Empty Then
                    fiyat3 = Format(rd(19), "000000.00")
                Else
                    fiyat3 = Format(0, "000000.00")
                End If
            End If

            Dim fiyat4 As String = "0"
            If Not rd(22) Is DBNull.Value And Not rd(22) Is Nothing And Not rd(22) Is String.Empty Then
                fiyat4 = Format(rd(22), "000000.00")
            Else
                If Not rd(21) Is DBNull.Value And Not rd(21) Is Nothing And Not rd(21) Is String.Empty Then
                    fiyat4 = Format(rd(21), "000000.00")
                Else
                    fiyat4 = Format(0, "000000.00")
                End If
            End If

            Dim fiyat5 As String = "0"
            If Not rd(24) Is DBNull.Value And Not rd(24) Is Nothing And Not rd(24) Is String.Empty Then
                fiyat5 = Format(rd(24), "000000.00")
            Else
                If Not rd(23) Is DBNull.Value And Not rd(23) Is Nothing And Not rd(23) Is String.Empty Then
                    fiyat5 = Format(rd(23), "000000.00")
                Else
                    fiyat5 = Format(0, "000000.00")
                End If
            End If

            Dim teminci As String = " "
            If Not rd(16) Is DBNull.Value And Not rd(16) Is Nothing And Not rd(16) Is String.Empty Then
                teminci = rd(16)
            End If

            'If satis_kdv <> Nothing And stok_code <> "" And stok_adi <> "" And fiyat <> Nothing And barkod <> "" And puan <> Nothing Then
            dt.Rows.Add(aliskdvgrp, satiskdvgrp, urun_tipi, stk_ana_grup, stk_alt_grup, puan, barkod, icerik, tipkontrol, stok_code, stok_adi, fiyat, birim_kod, katsayi, fiyat2, fiyat3, fiyat4, fiyat5, teminci)
            'End If
        End While
        cn.Close()
        Return dt
    End Function
    Public Sub Stok_Karti(ByVal Stok_Dosyasi As String, ByVal Atarih As String, ByVal Adepo As String, ByVal Afiyat As Integer, ByVal degisiklik As Boolean, ByVal secenek As Integer)
        Dim satirisareti1 As String = "01  1"
        Dim satirisareti2 As String = "02  1"
        Dim stokbilgileri As New DataTable
        stokbilgileri = StokBilgi(Atarih, Adepo, Afiyat, secenek)
        Dim stokkodu(stokbilgileri.Rows.Count) As String
        Dim eskistokkod(stokbilgileri.Rows.Count) As String
        Dim stokkartaciklama(stokbilgileri.Rows.Count) As String
        Dim extrastokkartiaciklama(stokbilgileri.Rows.Count) As String
        Dim posekraniaciklama(stokbilgileri.Rows.Count) As String
        Dim rafetiketiaciklama(stokbilgileri.Rows.Count) As String
        Dim terazietiketiaciklama(stokbilgileri.Rows.Count) As String
        Dim stokbolumu(stokbilgileri.Rows.Count) As String
        Dim reyontanimi(stokbilgileri.Rows.Count) As String
        Dim uruntipi(stokbilgileri.Rows.Count) As String
        Dim indirimgrubu As String = " " 'ok
        If Len(indirimgrubu) Then indirimgrubu += Space(8 - Len(indirimgrubu))
        Dim indirimtipi As String = "0" 'ok
        Dim indirimyuzdesi As String = "0,00" 'ok
        If Len(indirimyuzdesi) Then indirimyuzdesi += Space(15 - Len(indirimyuzdesi))
        Dim indirimtutari As String = "0,00" 'ok
        If Len(indirimtutari) Then indirimtutari += Space(15 - Len(indirimtutari))
        Dim reserved As String = "0" 'ok
        If Len(reserved) Then reserved += Space(6 - Len(reserved))
        Dim baglistokkodu As String = " " 'ok
        If Len(baglistokkodu) Then baglistokkodu += Space(24 - Len(baglistokkodu))
        Dim birim(stokbilgileri.Rows.Count) As String
        Dim icerik(stokbilgileri.Rows.Count) As String
        Dim birimboleni(stokbilgileri.Rows.Count) As String 'ok

        Dim birimcarpani As String = "0" 'ok
        If Len(birimcarpani) Then birimcarpani += Space(15 - Len(birimcarpani))
        Dim ikincibirimkodu As String = " " 'ok 
        If Len(ikincibirimkodu) Then ikincibirimkodu += Space(8 - Len(ikincibirimkodu))
        Dim ucuncubirimkodu As String = " " 'ok
        If Len(ucuncubirimkodu) Then ucuncubirimkodu += Space(8 - Len(ucuncubirimkodu))
        Dim bir_ikigeciskatsayi As String = "0" 'ok
        If Len(bir_ikigeciskatsayi) Then bir_ikigeciskatsayi += Space(12 - Len(bir_ikigeciskatsayi))
        Dim bir_ucgeciskatsayi As String = "0" 'ok
        If Len(bir_ucgeciskatsayi) Then bir_ucgeciskatsayi += Space(12 - Len(bir_ucgeciskatsayi))
        Dim bir_ikigeciskatsayicarpar As String = "0" 'ok
        Dim bir_ucgeciskatsayicarpar As String = "0" 'ok
        Dim satisfiyat1(stokbilgileri.Rows.Count) As String 'zorunlu
        Dim satisfiyat2(stokbilgileri.Rows.Count) As String 'zorunlu
        Dim satisfiyat3(stokbilgileri.Rows.Count) As String 'zorunlu
        Dim satisfiyat4(stokbilgileri.Rows.Count) As String 'zorunlu
        Dim satisfiyat5(stokbilgileri.Rows.Count) As String 'zorunlu

        'Dim satisfiyat2 As String = "0" 'ok
        'If Len(satisfiyat2) Then satisfiyat2 += Space(15 - Len(satisfiyat2))
        'Dim satisfiyat3 As String = "0" 'ok
        'If Len(satisfiyat3) Then satisfiyat3 += Space(15 - Len(satisfiyat3))
        'Dim satisfiyat4(stokbilgileri.Rows.Count) As String
        ''If Len(satisfiyat4) Then satisfiyat4 += Space(15 - Len(satisfiyat4))
        'Dim satisfiyat5 As String = "0" 'ok
        'If Len(satisfiyat5) Then satisfiyat5 += Space(15 - Len(satisfiyat5))
        Dim alisfiyat1 As String = "0" 'ok
        If Len(alisfiyat1) Then alisfiyat1 += Space(15 - Len(alisfiyat1))
        Dim alisfiyat2 As String = "0" 'ok
        If Len(alisfiyat2) Then alisfiyat2 += Space(15 - Len(alisfiyat2))
        Dim alisfiyat3 As String = "0" 'ok
        If Len(alisfiyat3) Then alisfiyat3 += Space(15 - Len(alisfiyat3))
        Dim alisfiyat4 As String = "0" 'ok 
        If Len(alisfiyat4) Then alisfiyat4 += Space(15 - Len(alisfiyat4))
        Dim alisfiyat5 As String = "0" 'ok
        If Len(alisfiyat5) Then alisfiyat5 += Space(15 - Len(alisfiyat5))
        Dim fiyatindex1 As String = "0 " 'ok 
        Dim fiyatindex2 As String = "0 " 'ok
        Dim fiyatindex3 As String = "0 " 'ok
        Dim fiyatindex4 As String = "0 " 'ok
        Dim fiyatindex5 As String = "0 " 'ok
        Dim fiyatindex1_1 As String = "0 " '
        Dim fiyatindex2_2 As String = "0 " 'ok
        Dim fiyatindex3_3 As String = "0 " 'ok
        Dim fiyatindex4_4 As String = "0 " 'ok
        Dim fiyatindex5_5 As String = "0 " 'ok
        Dim kdvdahil As String = "1023"
        If Len(kdvdahil) Then kdvdahil += Space(6 - Len(kdvdahil))
        Dim satiskdvgrpno(stokbilgileri.Rows.Count) As String 'zorunlu
        Dim aliskdvgrpno(stokbilgileri.Rows.Count) As String
        Dim kdvkullanimsekli As String = "0" 'ok 
        Dim izinliminsatisadet As String = "0" 'ok
        If Len(izinliminsatisadet) Then izinliminsatisadet += Space(15 - Len(izinliminsatisadet))
        Dim izinlimaxsatisadet As String = "0" 'ok
        If Len(izinlimaxsatisadet) Then izinlimaxsatisadet += Space(15 - Len(izinlimaxsatisadet))
        Dim kasiyermaxindyuzde As String = "0" 'ok
        If Len(kasiyermaxindyuzde) Then kasiyermaxindyuzde += Space(3 - Len(kasiyermaxindyuzde))
        Dim kasiyermaxind As String = "0" 'ok 
        If Len(kasiyermaxind) Then kasiyermaxind += Space(15 - Len(kasiyermaxind))
        Dim satisdurum As String = "0" 'ok
        Dim adetlisatisdurum As String = "0" 'ok
        Dim fiyatsatisdurum As String = "0" 'ok
        Dim iadekontrol As String = "0" 'ok
        Dim saticigiris As String = "0" 'ok 
        Dim kodsatis As String = "0" 'ok
        Dim indirimlisatis As String = "2" 'ok
        Dim urunsipariskontrol As String = "1" 'ok
        Dim temincikodu As String = " " '????????????????????????

        Dim kredisablon As String = "000000" '5 tane 0 eklenecek
        Dim teminsure As String = "000000000000000" '14 tane 0 ekle
        Dim sipariskatsayi As String = "000000" '5 tane 0 ekle
        Dim deposiparisseviye As String = "000000000000000" '14 tane 0 ekle
        Dim depokritikseviye As String = "000000000000000" '14 tane 0 ekle
        Dim depomaxseviye As String = "000000000000000" '14 tane 0 ekle
        Dim terazidurum(stokbilgileri.Rows.Count) As String
        Dim katsayi1 As String = "000000000000000" '14 tane 0 ekle
        Dim katsayi2 As String = "000000000000000" '14 tane 0 ekle
        Dim katsayi3 As String = "000000000000000" '14 tane 0 ekle
        Dim katsayi4 As String = "000000000000000" '14 tane 0 ekle
        Dim katsayi5 As String = "000000000000000" '14 tane 0 ekle
        Dim katsayi6 As String = "000000000000000" '14 tane 0 ekle
        Dim katsayi7 As String = "000000000000000" '14 tane 0 ekle
        Dim katsayi8 As String = "000000000000000" '14 tane 0 ekle
        Dim stkpuan(stokbilgileri.Rows.Count) As String
        Dim uretimbilgi As String = "000000" '5 tane 0 ekle
        'barkod bilgileri
        Dim iliskilistkkod(stokbilgileri.Rows.Count) As String  'zorunlu
        Dim barkod(stokbilgileri.Rows.Count) As String  'zorunlu
        Dim eskibarkod(stokbilgileri.Rows.Count) As String 'zorunlu 
        Dim birimmiktar(stokbilgileri.Rows.Count) As String  'zorunlu
        Dim barkodtip(stokbilgileri.Rows.Count) As String 'zorunlu
        Dim brkdfiyatbilgi As String = "0" 'zorunlu 'Ok
        Dim sirano As String = "1 " 'zorunlu  '+fiyat vardı??????
        'Dosya ya Yaz
        Dim filepath As String = Stok_Dosyasi & "\GNDPLUF.GTF"
        Dim sw As New StreamWriter(filepath, False, System.Text.Encoding.Default)
        sw.WriteLine("<SIGNATURE=GNDPLU.GDF><VERSION=220001>")

        For i As Integer = 0 To stokbilgileri.Rows.Count - 1

            temincikodu = stokbilgileri.Rows(i)("teminci")
            If Len(temincikodu) < 20 Then
                temincikodu += Space(20 - Len(temincikodu))
            Else
                temincikodu = Mid(temincikodu, 1, 20)
            End If

            stokkodu(i) = stokbilgileri.Rows(i)(9)
            stokkodu(i) = Trim(stokkodu(i))
            If Len(stokkodu(i)) > 24 Then
                stokkodu(i) = Left(stokkodu(i), 24)
            Else
                stokkodu(i) += Space(24 - Len(stokkodu(i)))
            End If
            eskistokkod(i) = stokbilgileri.Rows(i)(9)
            eskistokkod(i) = Trim(eskistokkod(i))
            If Len(eskistokkod(i)) > 24 Then
                eskistokkod(i) = Left(eskistokkod(i), 24)
            Else
                eskistokkod(i) += Space(24 - Len(eskistokkod(i)))
            End If
            stokkartaciklama(i) = stokbilgileri.Rows(i)(10)
            stokkartaciklama(i) = Trim(stokkartaciklama(i))
            If Len(stokkartaciklama(i)) > 40 Then
                stokkartaciklama(i) = Left(stokkartaciklama(i), 40)
            Else
                stokkartaciklama(i) += Space(40 - Len(stokkartaciklama(i)))
            End If
            extrastokkartiaciklama(i) = stokbilgileri.Rows(i)(10)
            extrastokkartiaciklama(i) = Trim(extrastokkartiaciklama(i))
            If Len(extrastokkartiaciklama(i)) > 40 Then
                extrastokkartiaciklama(i) = Left(extrastokkartiaciklama(i), 40)
            Else
                extrastokkartiaciklama(i) += Space(40 - Len(extrastokkartiaciklama(i)))
            End If
            posekraniaciklama(i) = stokbilgileri.Rows(i)(10)
            posekraniaciklama(i) = Trim(posekraniaciklama(i))
            If Len(posekraniaciklama(i)) > 20 Then
                posekraniaciklama(i) = Left(posekraniaciklama(i), 20)
            Else
                posekraniaciklama(i) += Space(20 - Len(posekraniaciklama(i)))
            End If
            rafetiketiaciklama(i) = stokbilgileri.Rows(i)(10)
            rafetiketiaciklama(i) = Trim(rafetiketiaciklama(i))
            If Len(rafetiketiaciklama(i)) > 20 Then
                rafetiketiaciklama(i) = Left(rafetiketiaciklama(i), 20)
            Else
                rafetiketiaciklama(i) += Space(20 - Len(rafetiketiaciklama(i)))
            End If
            terazietiketiaciklama(i) = stokbilgileri.Rows(i)(10)
            terazietiketiaciklama(i) = Trim(terazietiketiaciklama(i))
            If Len(terazietiketiaciklama(i)) > 16 Then
                terazietiketiaciklama(i) = Left(terazietiketiaciklama(i), 16)
            Else
                terazietiketiaciklama(i) += Space(16 - Len(terazietiketiaciklama(i)))
            End If
            stokbolumu(i) = stokbilgileri.Rows(i)(3)
            stokbolumu(i) = Trim(stokbolumu(i))
            If Len(stokbolumu(i)) > 8 Then
                stokbolumu(i) = Left(stokbolumu(i), 8)
            Else
                stokbolumu(i) += Space(8 - Len(stokbolumu(i)))
            End If
            reyontanimi(i) = stokbilgileri.Rows(i)(4)
            reyontanimi(i) = Trim(reyontanimi(i))
            If Len(reyontanimi(i)) > 8 Then
                reyontanimi(i) = Left(reyontanimi(i), 8)
            Else
                reyontanimi(i) += Space(8 - Len(reyontanimi(i)))
            End If
            satiskdvgrpno(i) = stokbilgileri.Rows(i)(1)
            satiskdvgrpno(i) = Trim(satiskdvgrpno(i))
            If Len(satiskdvgrpno(i)) > 3 Then
                satiskdvgrpno(i) = Left(satiskdvgrpno(i), 3)
            Else
                satiskdvgrpno(i) += Space(3 - Len(satiskdvgrpno(i)))
            End If

            aliskdvgrpno(i) = stokbilgileri.Rows(i)(0)
            aliskdvgrpno(i) = Trim(aliskdvgrpno(i))
            If Len(aliskdvgrpno(i)) > 3 Then
                aliskdvgrpno(i) = Left(aliskdvgrpno(i), 3)
            Else
                aliskdvgrpno(i) += Space(3 - Len(aliskdvgrpno(i)))
            End If

            stkpuan(i) = stokbilgileri.Rows(i)(5)
            stkpuan(i) = Trim(stkpuan(i))
            If Len(stkpuan(i)) > 15 Then
                stkpuan(i) = Left(stkpuan(i), 15)
            Else
                stkpuan(i) += Space(15 - Len(stkpuan(i)))
            End If
            iliskilistkkod(i) = stokbilgileri.Rows(i)(9)
            iliskilistkkod(i) = Trim(iliskilistkkod(i))
            If Len(iliskilistkkod(i)) > 24 Then
                iliskilistkkod(i) = Left(iliskilistkkod(i), 24)
            Else
                iliskilistkkod(i) += Space(24 - Len(iliskilistkkod(i)))
            End If

            satisfiyat1(i) = stokbilgileri.Rows(i)(11)
            satisfiyat1(i) = Trim(satisfiyat1(i))
            If Len(satisfiyat1(i)) > 15 Then
                satisfiyat1(i) = Left(satisfiyat1(i), 15)
            Else
                satisfiyat1(i) += Space(15 - Len(satisfiyat1(i)))
            End If

            satisfiyat2(i) = stokbilgileri.Rows(i)("fiyat2")
            satisfiyat2(i) = Trim(satisfiyat2(i))
            If Len(satisfiyat2(i)) > 15 Then
                satisfiyat2(i) = Left(satisfiyat2(i), 15)
            Else
                satisfiyat2(i) += Space(15 - Len(satisfiyat2(i)))
            End If

            satisfiyat3(i) = stokbilgileri.Rows(i)("fiyat3")
            satisfiyat3(i) = Trim(satisfiyat3(i))
            If Len(satisfiyat3(i)) > 15 Then
                satisfiyat3(i) = Left(satisfiyat3(i), 15)
            Else
                satisfiyat3(i) += Space(15 - Len(satisfiyat3(i)))
            End If

            satisfiyat4(i) = stokbilgileri.Rows(i)("fiyat4")
            satisfiyat4(i) = Trim(satisfiyat4(i))
            If Len(satisfiyat4(i)) > 15 Then
                satisfiyat4(i) = Left(satisfiyat4(i), 15)
            Else
                satisfiyat4(i) += Space(15 - Len(satisfiyat4(i)))
            End If


            satisfiyat5(i) = stokbilgileri.Rows(i)("fiyat5")
            satisfiyat5(i) = Trim(satisfiyat5(i))
            If Len(satisfiyat5(i)) > 15 Then
                satisfiyat5(i) = Left(satisfiyat5(i), 15)
            Else
                satisfiyat5(i) += Space(15 - Len(satisfiyat5(i)))
            End If


            barkod(i) = stokbilgileri.Rows(i)(6)
            barkod(i) = Trim(barkod(i))
            If Len(barkod(i)) > 24 Then
                barkod(i) = Left(barkod(i), 24)
            Else
                barkod(i) += Space(24 - Len(barkod(i)))
            End If
            eskibarkod(i) = stokbilgileri.Rows(i)(6)
            eskibarkod(i) = Trim(eskibarkod(i))
            If Len(eskibarkod(i)) > 24 Then
                eskibarkod(i) = Left(eskibarkod(i), 24)
            Else
                eskibarkod(i) += Space(24 - Len(eskibarkod(i)))
            End If
            birimmiktar(i) = stokbilgileri.Rows(i)(13)
            birimmiktar(i) = Trim(birimmiktar(i))
            If Len(birimmiktar(i)) > 6 Then
                birimmiktar(i) = Left(birimmiktar(i), 6)
            Else
                birimmiktar(i) += Space(6 - Len(birimmiktar(i)))
            End If
            barkodtip(i) = stokbilgileri.Rows(i)(8)

            barkodtip(i) = Trim(barkodtip(i))
            'Select Case barkodtip(i)
            '    Case 0
            '        barkodtip(i) = 1
            '    Case 1
            '        barkodtip(i) = 2
            '    Case 5
            '        barkodtip(i) = 4
            'End Select
            If Len(barkodtip(i)) > 1 Then
                barkodtip(i) = Left(barkodtip(i), 1)
            End If
            icerik(i) = stokbilgileri.Rows(i)(7)
            icerik(i) = Trim(icerik(i))
            If Len(icerik(i)) > 1 Then
                icerik(i) = Left(icerik(i), 1)
            End If
            If icerik(i) = 0 Then
                terazidurum(i) = 0
                adetlisatisdurum = 0
                birim(i) = 0
                birimboleni(i) = 0
                If Len(birimboleni(i)) Then birimboleni(i) += Space(15 - Len(birimboleni(i)))
            End If
            If icerik(i) = 1 Then
                terazidurum(i) = 1
                adetlisatisdurum = 2
                birim(i) = 1
                birimboleni(i) = 1000
                If Len(birimboleni(i)) Then birimboleni(i) += Space(15 - Len(birimboleni(i)))
            End If
            If icerik(i) = 2 Then
                terazidurum(i) = 1
                birim(i) = 1
                birimboleni(i) = 1000
                If Len(birimboleni(i)) Then birimboleni(i) += Space(15 - Len(birimboleni(i)))
            End If
            If icerik(i) = 3 Then
                terazidurum(i) = 2
                birim(i) = 0
                birimboleni(i) = 0
                If Len(birimboleni(i)) Then birimboleni(i) += Space(15 - Len(birimboleni(i)))
            End If
            If icerik(i) = 4 Then
                terazidurum(i) = 2
                birim(i) = 2
                birimboleni(i) = 1000
                If Len(birimboleni(i)) Then birimboleni(i) += Space(15 - Len(birimboleni(i)))
            End If
            If icerik(i) = 5 Then
                terazidurum(i) = 2
                birim(i) = 3
                birimboleni(i) = 1000
                If Len(birimboleni(i)) Then birimboleni(i) += Space(15 - Len(birimboleni(i)))
            End If
            uruntipi(i) = " "

            If Len(uruntipi(i)) > 8 Then
                uruntipi(i) = Left(uruntipi(i), 8)
            Else
                uruntipi(i) += Space(8 - Len(uruntipi(i)))
            End If
            Dim sonuc1 As String = satirisareti1 & stokkodu(i) & eskistokkod(i) & stokkartaciklama(i) & extrastokkartiaciklama(i) & posekraniaciklama(i) & rafetiketiaciklama(i) & terazietiketiaciklama(i) & stokbolumu(i) & reyontanimi(i) & uruntipi(i) & indirimgrubu & indirimtipi & indirimyuzdesi & indirimtutari & reserved & baglistokkodu & birim(i) & birimboleni(i) & birimcarpani & ikincibirimkodu & ucuncubirimkodu & bir_ikigeciskatsayi & bir_ucgeciskatsayi & bir_ikigeciskatsayicarpar & bir_ucgeciskatsayicarpar & satisfiyat1(i) & satisfiyat2(i) & satisfiyat3(i) & satisfiyat4(i) & satisfiyat5(i) & alisfiyat1 & alisfiyat2 & alisfiyat3 & alisfiyat4 & alisfiyat5 & fiyatindex1 & fiyatindex2 & fiyatindex3 & fiyatindex4 & fiyatindex5 & fiyatindex1_1 & fiyatindex2_2 & fiyatindex3_3 & fiyatindex4_4 & fiyatindex5_5 & kdvdahil & satiskdvgrpno(i) & aliskdvgrpno(i) & kdvkullanimsekli & izinliminsatisadet & izinlimaxsatisadet & kasiyermaxindyuzde & kasiyermaxind & satisdurum & adetlisatisdurum & fiyatsatisdurum & iadekontrol & saticigiris & kodsatis & indirimlisatis & urunsipariskontrol & temincikodu & kredisablon & teminsure & sipariskatsayi & deposiparisseviye & depokritikseviye & depomaxseviye & terazidurum(i) & katsayi1 & katsayi2 & katsayi3 & katsayi4 & katsayi5 & katsayi6 & katsayi7 & katsayi8 & stkpuan(i) & uretimbilgi
            Dim sonuc2 As String = satirisareti2 & iliskilistkkod(i) & barkod(i) & eskibarkod(i) & birimmiktar(i) & barkodtip(i) & brkdfiyatbilgi & sirano & satisfiyat1(i)
            sw.WriteLine(sonuc1)
            sw.WriteLine(sonuc2)

            Frm_Genius_Send.Prg_Percent = i
        Next
        '''''birim olarak birim id mi alınacak yoksa birim kodu mu?birim kodu olursa tip uyusmazlıgı var!
        '''''ayrıca temıncı kodu textte degıskendı.????
        ''''birim miktar yerine katsssayı aldım?????????

        sw.Close()


    End Sub
    Private Function musteribilgi_alma(ByVal tarih As String, ByVal depo As String) As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("Musteri Kodu", GetType(String))
        dt.Columns.Add("Musteri Adi", GetType(String))
        dt.Columns.Add("Musteri Tipi", GetType(Int16))
        dt.Columns.Add("Musteri Grup Kodu", GetType(String))
        dt.Columns.Add("Musteri Vergi Daire", GetType(String))
        dt.Columns.Add("Musteri Eposta", GetType(String))
        dt.Columns.Add("Musteri Web", GetType(String))
        dt.Columns.Add("Musteri Vergi No", GetType(String))
        dt.Columns.Add("Musteri Sozlesme Tarihi", GetType(DateTime))
        dt.Columns.Add("Musteri Adres", GetType(String))
        dt.Columns.Add("Musteri Il", GetType(String))
        dt.Columns.Add("Musteri Tel1", GetType(String))
        dt.Columns.Add("Musteri Tel2", GetType(String))
        dt.Columns.Add("Musteri Fax", GetType(String))
        dt.Columns.Add("Musteri Sicil No", GetType(String))
        dt.Columns.Add("Musteri Kredi Limit", GetType(Decimal))
        dt.Columns.Add("Musteri Indirim Orani", GetType(Integer))
        Dim cn As New OleDbConnection(Cnn_String)
        cn.Open()
        Dim cmd As New OleDbCommand("EXEC PW_" & Firma_Kod & "_GENIUS_EXP @P1='" & tarih & "',@P2='" & depo & "',@P3=0,@P4=2", cn)
        Dim rd As OleDbDataReader
        rd = cmd.ExecuteReader
        While rd.Read
            Dim carikod As String
            If rd(0) Is DBNull.Value OrElse rd(0) Is Nothing OrElse rd(0) Is String.Empty Then
                carikod = " "
            Else
                carikod = CStr(rd(0))
            End If
            Dim cariad As String
            If rd(1) Is DBNull.Value OrElse rd(1) Is Nothing OrElse rd(1) Is String.Empty Then
                cariad = " "
            Else
                cariad = CStr(rd(1))
            End If
            Dim caritip As Int16
            If rd(2) Is DBNull.Value OrElse rd(2) Is Nothing OrElse rd(2) Is String.Empty Then
                caritip = 0
            Else
                caritip = CInt(rd(2))
            End If
            Dim carigrupkod As String
            If rd(3) Is DBNull.Value OrElse rd(3) Is Nothing OrElse rd(3) Is String.Empty Then
                carigrupkod = " "
            Else
                carigrupkod = CStr(rd(3))
            End If
            Dim carivergidaire As String
            If rd(4) Is DBNull.Value OrElse rd(4) Is Nothing OrElse rd(4) Is String.Empty Then
                carivergidaire = " "
            Else
                carivergidaire = CStr(rd(4))
            End If
            Dim carieposta As String
            If rd(5) Is DBNull.Value OrElse rd(5) Is Nothing OrElse rd(5) Is String.Empty Then
                carieposta = " "
            Else
                carieposta = CStr(rd(5))
            End If
            Dim cariweb As String
            If rd(6) Is DBNull.Value OrElse rd(6) Is Nothing OrElse rd(6) Is String.Empty Then
                cariweb = " "
            Else
                cariweb = CStr(rd(6))
            End If
            Dim carivergino As String
            If rd(7) Is DBNull.Value OrElse rd(7) Is Nothing OrElse rd(7) Is String.Empty Then
                carivergino = " "
            Else
                carivergino = CStr(rd(7))
            End If
            Dim carisozlesmetarih As DateTime
            If rd(8) Is DBNull.Value OrElse rd(8) Is Nothing OrElse rd(8) Is String.Empty Then
                carisozlesmetarih = " "
            Else
                carisozlesmetarih = rd(8)
            End If
            carisozlesmetarih = FormatDateTime(carisozlesmetarih, DateFormat.ShortDate)
            Dim cariadres As String
            If rd(9) Is DBNull.Value OrElse rd(9) Is Nothing OrElse rd(9) Is String.Empty Then
                cariadres = " "
            Else
                cariadres = CStr(rd(9))
            End If
            Dim cariil As String
            If rd(10) Is DBNull.Value OrElse rd(10) Is Nothing OrElse rd(10) Is String.Empty Then
                cariil = " "
            Else
                cariil = CStr(rd(10))
            End If
            Dim caritel1 As String
            If rd(11) Is DBNull.Value OrElse rd(11) Is Nothing OrElse rd(11) Is String.Empty Then
                caritel1 = " "
            Else
                caritel1 = CStr(rd(11))
            End If
            Dim caritel2 As String
            If rd(12) Is DBNull.Value OrElse rd(12) Is Nothing OrElse rd(12) Is String.Empty Then
                caritel2 = " "
            Else
                caritel2 = CStr(rd(12))
            End If
            Dim carifax As String
            If rd(13) Is DBNull.Value OrElse rd(13) Is Nothing OrElse rd(13) Is String.Empty Then
                carifax = " "
            Else
                carifax = CStr(rd(13))
            End If
            Dim carisicil As String
            If rd(14) Is DBNull.Value OrElse rd(14) Is Nothing OrElse rd(14) Is String.Empty Then
                carisicil = " "
            Else
                carisicil = CStr(rd(14))
            End If
            Dim carikredilimit As Decimal
            If rd(15) Is DBNull.Value OrElse rd(15) Is Nothing OrElse rd(15) Is String.Empty Then
                carikredilimit = 0.0
            Else
                carikredilimit = CDec(rd(15))
            End If
            Dim cariiskonto As Integer
            If rd(16) Is DBNull.Value OrElse rd(16) Is Nothing OrElse rd(16) Is String.Empty Then
                cariiskonto = 0
            Else
                cariiskonto = CInt(rd(16))
            End If
            dt.Rows.Add(carikod, cariad, caritip, carigrupkod, carivergidaire, carieposta, cariweb, carivergino, carisozlesmetarih, cariadres, cariil, caritel1, caritel2, carifax, carisicil, carikredilimit, cariiskonto)
        End While
        cn.Close()
        Return dt
    End Function
    Public Sub musterikart(ByVal FPath As String, ByVal Atarih As String, ByVal Adepo As String, ByVal degisiklik As Boolean)
        Dim islemtur1 As String = "01  0"
        Dim islemtur2 As String = "02  0"
        Dim musteribilgi As New DataTable
        musteribilgi = musteribilgi_alma(Atarih, Adepo)
        Dim carikod(musteribilgi.Rows.Count) As String
        Dim carieskikod(musteribilgi.Rows.Count) As String
        Dim cariad(musteribilgi.Rows.Count) As String
        Dim carigrpkod As String = " "
        If Len(carigrpkod) Then carigrpkod += Space(8 - Len(carigrpkod))
        Dim caritip As String = "1"
        If Len(caritip) Then caritip += Space(8 - Len(caritip))

        Dim kredisablon As String = " "
        If Len(kredisablon) Then kredisablon += Space(6 - Len(kredisablon))
        Dim taksitodememetod As String = "0"
        Dim taksitodememetodparam As String = "000"
        Dim sozlesmetarih(musteribilgi.Rows.Count) As String
        Dim adres1(musteribilgi.Rows.Count) As String
        Dim adres2(musteribilgi.Rows.Count) As String
        Dim adres3(musteribilgi.Rows.Count) As String
        Dim il(musteribilgi.Rows.Count) As String
        Dim postakod As String = " "
        If Len(postakod) Then postakod += Space(10 - Len(postakod))
        Dim tel1(musteribilgi.Rows.Count) As String
        Dim tel2(musteribilgi.Rows.Count) As String
        Dim fax(musteribilgi.Rows.Count) As String
        Dim eposta(musteribilgi.Rows.Count) As String
        Dim web(musteribilgi.Rows.Count) As String
        Dim vergidaire(musteribilgi.Rows.Count) As String
        Dim vergino(musteribilgi.Rows.Count) As String
        Dim sicilno(musteribilgi.Rows.Count) As String
        Dim kredilimit(musteribilgi.Rows.Count) As String
        Dim iskonto(musteribilgi.Rows.Count) As String
        Dim indirimtipi As String = "1"
        Dim reserved As String = "0"
        Dim index As String = "0"
        Dim kartkod(musteribilgi.Rows.Count) As String
        Dim eskikartkod(musteribilgi.Rows.Count) As String
        Dim ckod(musteribilgi.Rows.Count) As String
        Dim kartismi(musteribilgi.Rows.Count) As String
        Dim karttipi As String = "0"
        Dim gecerliliktarih As String = " "
        If Len(gecerliliktarih) Then gecerliliktarih += Space(14 - Len(gecerliliktarih))
        Dim verilistarih(musteribilgi.Rows.Count) As String
        Dim kartdurum As String = "2"
        Dim filepath As String = FPath & "\GNDCSTMERS.GTF"
        Dim sw As New StreamWriter(filepath, degisiklik, System.Text.Encoding.Default)
        sw.WriteLine("<SIGNATURE=GNDCSTMERS.GDF><VERSION=220001>")
        For i As Integer = 0 To musteribilgi.Rows.Count - 1
            carikod(i) = musteribilgi.Rows(i)(0)
            carikod(i) = Trim(carikod(i))
            If Len(carikod(i)) > 24 Then
                carikod(i) = Left(carikod(i), 24)
            Else
                carikod(i) += Space(24 - Len(carikod(i)))
            End If
            carieskikod(i) = musteribilgi.Rows(i)(0)
            carieskikod(i) = Trim(carieskikod(i))
            If Len(carieskikod(i)) > 24 Then
                carieskikod(i) = Left(carieskikod(i), 24)
            Else
                carieskikod(i) += Space(24 - Len(carieskikod(i)))
            End If

            cariad(i) = musteribilgi.Rows(i)(1)
            cariad(i) = Trim(cariad(i))
            If Len(cariad(i)) > 30 Then
                cariad(i) = Left(cariad(i), 30)
            Else
                cariad(i) += Space(30 - Len(cariad(i)))
            End If
            'carigrpkod(i) = musteribilgi.Rows(i)(3)
            'carigrpkod(i) = Trim(carigrpkod(i))
            'If Len(carigrpkod(i)) > 8 Then
            '    carigrpkod(i) = Left(carigrpkod(i), 8)
            'Else
            '    carigrpkod(i) += Space(8 - Len(carigrpkod(i)))
            'End If

            sozlesmetarih(i) = musteribilgi.Rows(i)(8)
            sozlesmetarih(i) = Trim(sozlesmetarih(i))
            'sozlesmetarih(i) = Format(sozlesmetarih(i), "")
            If Len(sozlesmetarih(i)) > 14 Then
                sozlesmetarih(i) = Left(sozlesmetarih(i), 14)
            Else
                sozlesmetarih(i) += Space(14 - Len(sozlesmetarih(i)))
            End If

            adres1(i) = musteribilgi.Rows(i)(9)
            adres1(i) = Trim(adres1(i))
            adres1(i) = adres1(i).Replace(vbCrLf, "")

            If Len(adres1(i)) > 30 Then
                adres1(i) = Left(adres1(i), 30)
            Else
                adres1(i) += Space(30 - Len(adres1(i)))
            End If
            adres2(i) = musteribilgi.Rows(i)(9)
            adres2(i) = Trim(adres2(i))
            adres2(i) = adres2(i).Replace(vbCrLf, "")

            If Len(adres2(i)) > 30 Then
                adres2(i) = Left(adres2(i), 30)
            Else
                adres2(i) += Space(30 - Len(adres2(i)))
            End If
            adres3(i) = musteribilgi.Rows(i)(9)
            adres3(i) = Trim(adres3(i))
            adres3(i) = adres3(i).Replace(vbCrLf, "")

            If Len(adres3(i)) > 30 Then
                adres3(i) = Left(adres3(i), 30)
            Else
                adres3(i) += Space(30 - Len(adres3(i)))
            End If
            tel1(i) = musteribilgi.Rows(i)(11)
            tel1(i) = Trim(tel1(i))
            If Len(tel1(i)) > 25 Then
                tel1(i) = Left(tel1(i), 25)
            Else
                tel1(i) += Space(25 - Len(tel1(i)))
            End If
            il(i) = musteribilgi.Rows(i)(10)
            il(i) = Trim(il(i))
            If Len(il(i)) > 20 Then
                il(i) = Left(il(i), 20)
            Else
                il(i) += Space(20 - Len(il(i)))
            End If
            tel2(i) = musteribilgi.Rows(i)(12)
            tel2(i) = Trim(tel2(i))
            If Len(tel2(i)) > 25 Then
                tel2(i) = Left(tel2(i), 25)
            Else
                tel2(i) += Space(25 - Len(tel2(i)))
            End If
            fax(i) = musteribilgi.Rows(i)(13)
            fax(i) = Trim(tel2(i))
            If Len(fax(i)) > 25 Then
                fax(i) = Left(fax(i), 25)
            Else
                fax(i) += Space(25 - Len(fax(i)))
            End If
            eposta(i) = musteribilgi.Rows(i)(5)
            eposta(i) = Trim(eposta(i))
            If Len(eposta(i)) > 25 Then
                eposta(i) = Left(eposta(i), 25)
            Else
                eposta(i) += Space(25 - Len(eposta(i)))
            End If
            web(i) = musteribilgi.Rows(i)(6)
            web(i) = Trim(web(i))
            If Len(web(i)) > 50 Then
                web(i) = Left(web(i), 50)
            Else
                web(i) += Space(50 - Len(web(i)))
            End If
            vergidaire(i) = musteribilgi.Rows(i)(4)
            vergidaire(i) = Trim(vergidaire(i))
            If Len(vergidaire(i)) > 20 Then
                vergidaire(i) = Left(vergidaire(i), 20)
            Else
                vergidaire(i) += Space(20 - Len(vergidaire(i)))
            End If
            vergino(i) = musteribilgi.Rows(i)(7)
            vergino(i) = Trim(vergino(i))
            If Len(vergino(i)) > 12 Then
                vergino(i) = Left(vergino(i), 12)
            Else
                vergino(i) += Space(12 - Len(vergino(i)))
            End If
            sicilno(i) = musteribilgi.Rows(i)(14)
            sicilno(i) = Trim(sicilno(i))
            If Len(sicilno(i)) > 20 Then
                sicilno(i) = Left(sicilno(i), 20)
            Else
                sicilno(i) += Space(20 - Len(sicilno(i)))
            End If
            kredilimit(i) = musteribilgi.Rows(i)(15)
            kredilimit(i) = Trim(kredilimit(i))
            'If Len(kredilimit(i)) > 15 Then
            '    kredilimit(i) = Left(kredilimit(i), 15)
            'Else
            '    kredilimit(i) += Space(15 - Len(kredilimit(i)))
            'End If
            kredilimit(i) = "000000000000000" + kredilimit(i)
            If Len(kredilimit(i)) <> 15 Then kredilimit(i) = Right(kredilimit(i), 15)
            iskonto(i) = musteribilgi.Rows(i)(16)
            iskonto(i) = Trim(iskonto(i))
            If Len(iskonto(i)) > 6 Then
                iskonto(i) = Left(iskonto(i), 6)
            Else
                iskonto(i) += Space(6 - Len(iskonto(i)))
            End If
            iskonto(i) = Format(iskonto(i), "0,0.00")
            kartkod(i) = musteribilgi.Rows(i)(0)
            kartkod(i) = Trim(kartkod(i))
            If Len(kartkod(i)) > 24 Then
                kartkod(i) = Left(kartkod(i), 24)
            Else
                kartkod(i) += Space(24 - Len(kartkod(i)))
            End If
            eskikartkod(i) = musteribilgi.Rows(i)(0)
            eskikartkod(i) = Trim(eskikartkod(i))
            If Len(eskikartkod(i)) > 24 Then
                eskikartkod(i) = Left(eskikartkod(i), 24)
            Else
                eskikartkod(i) += Space(24 - Len(eskikartkod(i)))
            End If
            ckod(i) = musteribilgi.Rows(i)(0)
            ckod(i) = Trim(ckod(i))
            If Len(ckod(i)) > 24 Then
                ckod(i) = Left(ckod(i), 24)
            Else
                ckod(i) += Space(24 - Len(ckod(i)))
            End If
            kartismi(i) = musteribilgi.Rows(i)(1)
            kartismi(i) = Trim(kartismi(i))
            If Len(kartismi(i)) > 30 Then
                kartismi(i) = Left(kartismi(i), 30)
            Else
                kartismi(i) += Space(30 - Len(kartismi(i)))
            End If
            verilistarih(i) = musteribilgi.Rows(i)(8)
            verilistarih(i) = Trim(verilistarih(i))
            If Len(verilistarih(i)) > 14 Then
                verilistarih(i) = Left(verilistarih(i), 14)
            Else
                verilistarih(i) += Space(14 - Len(verilistarih(i)))
            End If
            Dim ilksatir As String = islemtur1 & carikod(i) & carieskikod(i) & cariad(i) & carigrpkod & caritip & kredisablon & taksitodememetod & taksitodememetodparam & sozlesmetarih(i) & adres1(i) & adres2(i) & adres3(i) & il(i) & postakod & tel1(i) & tel2(i) & fax(i) & eposta(i) & web(i) & vergidaire(i) & vergino(i) & sicilno(i) & kredilimit(i) & iskonto(i) & indirimtipi & reserved & index
            Dim ikincisatir As String = islemtur2 & kartkod(i) & eskikartkod(i) & ckod(i) & kartismi(i) & karttipi & gecerliliktarih & verilistarih(i) & kartdurum

            sw.WriteLine(ilksatir)
            sw.WriteLine(ikincisatir)
            Frm_Genius_Send.Prg_Percent = i
        Next
        sw.Close()
    End Sub
    Private Function anagrupbilgi_alma(ByVal tarih As String, ByVal depo As String, ByVal fyt As Integer) As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("Ana Grup Kodu", GetType(String))
        dt.Columns.Add("Ana Grup Adi", GetType(String))
        Dim cn As New OleDbConnection(Cnn_String)
        cn.Open()
        Dim cmd As New OleDbCommand("EXEC PW_" & Firma_Kod & "_GENIUS_EXP @P1='" & tarih & "',@P2='" & depo & "',@P3=" & fyt & ",@P4=1", cn)
        Dim rd As OleDbDataReader
        rd = cmd.ExecuteReader
        While rd.Read
            Dim anakod As String
            If rd(0) Is DBNull.Value OrElse rd(0) Is Nothing OrElse rd(0) Is String.Empty Then
                anakod = " "
            Else
                anakod = CStr(rd(0))
            End If
            Dim anaad As String
            If rd(1) Is DBNull.Value OrElse rd(1) Is Nothing OrElse rd(1) Is String.Empty Then
                anaad = " "
            Else
                anaad = CStr(rd(1))
            End If
            dt.Rows.Add(anakod, anaad)
        End While
        cn.Close()
        Return dt
    End Function
    Public Sub anagrup_kart(ByVal Fpath As String, ByVal Atarih As String, ByVal Adepo As String, ByVal degisiklik As Boolean)
        Dim islemturu As String = "01  0"
        Dim anagrupbilgi As New DataTable
        anagrupbilgi = anagrupbilgi_alma(Atarih, Adepo, 1)
        Dim bolumkod(anagrupbilgi.Rows.Count) As String
        Dim eskibolumkod(anagrupbilgi.Rows.Count) As String
        Dim kullanimdurum As String = "0"
        Dim aciklama(anagrupbilgi.Rows.Count) As String
        Dim kredisablonkodu As String = "0"
        Dim indirimgrubu As String = " "
        If Len(indirimgrubu) Then indirimgrubu += Space(8 - Len(indirimgrubu))
        Dim baglikdvgrubu As String = "0"
        If Len(baglikdvgrubu) Then baglikdvgrubu += Space(6 - Len(baglikdvgrubu))
        Dim indirimturu As String = "0"
        If Len(indirimturu) Then indirimturu += Space(6 - Len(indirimturu))
        Dim filepath As String = Fpath & "\GNDDEP.GTF"
        Dim sw As New StreamWriter(filepath, degisiklik, System.Text.Encoding.Default)
        sw.WriteLine("<SIGNATURE=GNDDEP.GTF><VERSION=220001>")
        For i As Integer = 0 To anagrupbilgi.Rows.Count - 1
            bolumkod(i) = anagrupbilgi.Rows(i)(0)
            bolumkod(i) = Trim(bolumkod(i))
            If Len(bolumkod(i)) > 8 Then
                bolumkod(i) = Left(bolumkod(i), 8)
            Else
                bolumkod(i) += Space(8 - Len(bolumkod(i)))
            End If
            eskibolumkod(i) = anagrupbilgi.Rows(i)(0)
            eskibolumkod(i) = Trim(eskibolumkod(i))
            If Len(eskibolumkod(i)) > 8 Then
                eskibolumkod(i) = Left(eskibolumkod(i), 8)
            Else
                eskibolumkod(i) += Space(8 - Len(eskibolumkod(i)))
            End If
            aciklama(i) = anagrupbilgi.Rows(i)(1)
            aciklama(i) = Trim(aciklama(i))
            If Len(aciklama(i)) > 20 Then
                aciklama(i) = Left(aciklama(i), 20)
            Else
                aciklama(i) += Space(20 - Len(aciklama(i)))
            End If
            Dim sonuc As String = islemturu & bolumkod(i) & eskibolumkod(i) & kullanimdurum & aciklama(i) & kredisablonkodu & indirimgrubu & baglikdvgrubu & indirimturu
            sw.WriteLine(sonuc)
            Frm_Genius_Send.Prg_Percent = i
        Next
        sw.Close()
    End Sub
    Private Function altgrupbilgi_alma(ByVal tarih As String, ByVal depo As String, ByVal fyt As Integer) As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("Alt Grup Kodu", GetType(String))
        dt.Columns.Add("Alt Grup Adi", GetType(String))
        Dim cn As New OleDbConnection(Cnn_String)
        cn.Open()
        Dim cmd As New OleDbCommand("EXEC PW_" & Firma_Kod & "_GENIUS_EXP @P1='" & tarih & "',@P2='" & depo & "',@P3=" & fyt & ",@P4=3", cn)
        Dim rd As OleDbDataReader
        rd = cmd.ExecuteReader
        While rd.Read
            Dim altkod As String
            If rd(0) Is DBNull.Value OrElse rd(0) Is Nothing OrElse rd(0) Is String.Empty Then
                altkod = " "
            Else
                altkod = CStr(rd(0))
            End If
            Dim altad As String
            If rd(1) Is DBNull.Value OrElse rd(1) Is Nothing OrElse rd(1) Is String.Empty Then
                altad = " "
            Else
                altad = CStr(rd(1))
            End If
            dt.Rows.Add(altkod, altad)
        End While
        cn.Close()
        Return dt
    End Function
    Public Sub altgrup_kart(ByVal Fpath As String, ByVal Atarih As String, ByVal Adepo As String, ByVal degisiklik As Boolean)
        Dim islemturu As String = "01  0"
        Dim altgrupbilgi As New DataTable
        altgrupbilgi = altgrupbilgi_alma(Atarih, Adepo, 1)
        Dim reyonkod(altgrupbilgi.Rows.Count) As String
        Dim eskireyonkod(altgrupbilgi.Rows.Count) As String
        Dim kullanimdurum As String = "0"
        Dim aciklama(altgrupbilgi.Rows.Count) As String
        Dim kredisablonkodu As String = "0"
        Dim indirimgrubu As String = " "
        If Len(indirimgrubu) Then indirimgrubu += Space(8 - Len(indirimgrubu))
        Dim baglikdvgrubu As String = "0"
        If Len(baglikdvgrubu) Then baglikdvgrubu += Space(6 - Len(baglikdvgrubu))
        Dim indirimturu As String = "0"
        If Len(indirimturu) Then indirimturu += Space(6 - Len(indirimturu))

        Dim filepath As String = Fpath & "\GNDRYN.GTF"
        Dim sw As New StreamWriter(filepath, degisiklik, System.Text.Encoding.Default)
        sw.WriteLine("<SIGNATURE=GNDRYN.GTF><VERSION=220001>")
        For i As Integer = 0 To altgrupbilgi.Rows.Count - 1
            reyonkod(i) = altgrupbilgi.Rows(i)(0)
            reyonkod(i) = Trim(reyonkod(i))
            If Len(reyonkod(i)) > 8 Then
                reyonkod(i) = Left(reyonkod(i), 8)
            Else
                reyonkod(i) += Space(8 - Len(reyonkod(i)))
            End If
            eskireyonkod(i) = altgrupbilgi.Rows(i)(0)
            eskireyonkod(i) = Trim(eskireyonkod(i))
            If Len(eskireyonkod(i)) > 8 Then
                eskireyonkod(i) = Left(eskireyonkod(i), 8)
            Else
                eskireyonkod(i) += Space(8 - Len(eskireyonkod(i)))
            End If
            aciklama(i) = altgrupbilgi.Rows(i)(1)
            aciklama(i) = Trim(aciklama(i))
            If Len(aciklama(i)) > 20 Then
                aciklama(i) = Left(aciklama(i), 20)
            Else
                aciklama(i) += Space(20 - Len(aciklama(i)))
            End If
            Dim sonuc As String = islemturu & reyonkod(i) & eskireyonkod(i) & kullanimdurum & aciklama(i) & kredisablonkodu & indirimgrubu & baglikdvgrubu & indirimturu
            sw.WriteLine(sonuc)
            Frm_Genius_Send.Prg_Percent = i
        Next
        sw.Close()
    End Sub
    'yardımcı sub ve fonksiyonlar
    Private Function Stokkod_Bul(ByVal barkod As String) As String
        Dim str_sql As String
        str_sql = "SELECT     PW_" & Firma_Kod & "_STOK.stok_code " _
                & " FROM         PW_" & Firma_Kod & "_STOK INNER JOIN PW_" & Firma_Kod & "_BARKOD ON PW_" & Firma_Kod & "_STOK.stok_id = PW_" & Firma_Kod & "_BARKOD.stok_id " _
                & " WHERE     (PW_" & Firma_Kod & "_BARKOD.barkod = '" & barkod & "')"

        Dim cn As New OleDbConnection(Cnn_String)
        Dim adapter As New OleDbDataAdapter(str_sql, cn)
        Dim ds As New DataSet
        cn.Open()
        adapter.Fill(ds)
        Dim stokkod As String

        If ds.Tables.Count > 0 Then
            If ds.Tables(0).Rows.Count > 0 Then
                If Not ds.Tables(0).Rows(0)(0) Is DBNull.Value Then
                    stokkod = ds.Tables(0).Rows(0)(0)
                Else
                    stokkod = ""
                End If
            Else
                stokkod = ""
            End If
        Else
            stokkod = ""
        End If
        cn.Close()
        Return stokkod
    End Function
    Private Sub Depo_list2()
        Try
            Dim cn As New OleDbConnection(Cnn_String)
            Dim cmd As New OleDbCommand
            cmd.Connection = cn
            cn.Open()
            cmd.CommandText = "EXEC PW_" & Firma_Kod & "_DEPO_LIST @P1='',@P2=4,@P3=''"
            Dim rd As OleDbDataReader = cmd.ExecuteReader
            While rd.Read
                Stack_Depo_kod.Push(rd(0))
                Stack_Depo_id.Push(rd(2))
            End While
            cn.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


End Class
